
/**
 * AppleIIGo
 * Silentype Printer Interface Card class
 * (C) 2008 by Marc S. Ressl (mressl@umich.edu)
 * Released under the GPL
 */

#include "SilentypeInterfaceCard.h"

SilentypeInterfaceCard::SilentypeInterfaceCard(Motherboard * motherboard,
											   char * slotDeviceName) :
SlotDevice(motherboard, slotDeviceName) {
}

void SilentypeInterfaceCard::onMemoryRequested() {
	romMemoryOffset = 
		motherboard->getMemory()->requestMemory(SILENTYPE_ROM_BYTENUM);
	ramMemoryOffset = 
		motherboard->getMemory()->requestMemory(SILENTYPE_RAM_BYTENUM);
}

void SilentypeInterfaceCard::onMemoryAllocated() {
	romMemory = motherboard->getMemory()->getMemory(romMemoryOffset);
	ramMemory = motherboard->getMemory()->getMemory(ramMemoryOffset);
	char * romImage = "Apple Silentype Printer Interface Card ROM.bin";
	motherboard->getResources()->readResource(romMemory, 
											  SILENTYPE_ROM_BYTENUM,
											  romImage);
}

void SilentypeInterfaceCard::onResetAsserted(bool isRestart) {
	if (!isRestart)
		return;
	
	for (UINT32 index = 0; index < SILENTYPE_RAM_BYTENUM; index++)
		ramMemory[index] = 0;
}

void SilentypeInterfaceCard::writeMemory(UINT16 address, UINT8 value) {
	if ((address & 0xf00) == 0xf00)
		ramMemory[address & 0xff] = value;
}

UINT8 SilentypeInterfaceCard::readMemory(UINT16 address) {
	if ((address & 0xf00) == 0xf00)
		return ramMemory[address & 0xff];
	else
		return romMemory[address & 0x7ff];
}
